package com.example.paopao.consumer.memer.controller;

import com.example.paopao.common.pojo.security.CurrenPrincipal;
import com.example.paopao.common.web.JsonResult;
import com.example.paopao.consumer.memer.pojo.vo.IntegralVO;
import com.example.paopao.consumer.memer.pojo.vo.ResultIntegrals;
import com.example.paopao.consumer.memer.service.IIntegralsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/integrals/")
@Api("5.会员中心")
public class IntegralsController {

    @Autowired
    private IIntegralsService integralsService;

    @GetMapping("get")
    @ApiOperation("获取个人会员编号以及积分")
    @PreAuthorize("hasAuthority('/user/contact')")
    public JsonResult getUserIntegrals(@AuthenticationPrincipal CurrenPrincipal currenPrincipal){
        ResultIntegrals data = integralsService.getIntegrals(currenPrincipal.getUserId());
        return JsonResult.ok(data);
    }
    
    @GetMapping("integral-list")
    @ApiOperation("获取积分充值单")
    public JsonResult listIntegral(){
        List<IntegralVO> data = integralsService.listIntegral();
        return JsonResult.ok(data);
    }

    @ApiOperation("消费记录")
    @GetMapping("get-intracha")
    public JsonResult getIntracha(@AuthenticationPrincipal CurrenPrincipal currenPrincipal){
        return JsonResult.ok(integralsService.listIntracha(currenPrincipal.getUserId()));
    }
}
